<template>
  <div class="container">
    <div class="opt-area-02">
      <div class="right-con">
        <div class="input-frame" style="width: 164px">
          <Input type="text" @on-click="selectlist(1)" placeholder="请输入姓名" style="width: 164px" v-model="params.name" icon="ios-search"/>
        </div>
        <div class="input-frame" style="width: 164px">
          <Input type="text" @on-click="selectlist(1)" placeholder="请输入电话号码" style="width: 164px" v-model="params.mobile" icon="ios-search"/>
        </div>
        <div class="input-frame" style="width: 164px">
          <Input type="text" @on-click="selectlist(1)" placeholder="订单编号" style="width: 164px" v-model="params.code" icon="ios-search"/>
        </div>
        <div class="input-frame" style="width: 164px">
          <Input type="text" @on-click="selectlist(1)" placeholder="事项id" style="width: 164px" v-model="params.item_id" icon="ios-search"/>
        </div>
        <Button type="info" size="small" @click="selectlist(1)" style="margin-top: 5px;margin-right:5px">搜索</Button>
        <Button type="info" size="small" @click="selectlist(1)" style="margin-top: 5px;margin-right:5px">刷新</Button>
      </div>
    </div>
    <Table :loading="countData.loading" border :columns="columns1" :data="dataList" size="small" ref="table">
      <template slot-scope="{ row }" slot="state">
        <span v-if="row.state == '0'">未备份</span>
        <span v-if="row.state > 0">已备份</span>
      </template>
      <template slot="action" slot-scope="{ row }">
        <Row style="margin-bottom: 5px; margin-top: 2px">
          <Button class="table-action-btn" type="info" size="small" @click="addUnderWriter(row)">备份</Button>
        </Row>
      </template>
    </Table>
    <template>
      <Row v-if="loadData == true">
        <Col class="demo-spin-col" span="8" offset="8">
          <Spin fix>
            <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
            <div>查询中...</div>
          </Spin>
        </Col>
      </Row>
    </template>
  </div>
</template>

<script>

import { findBfList, savebf } from '@/api/mainv3'

export default {
  name: 'index',
  data () {
    return {
      modal1: false,
      disabledShow: false,
      params: { name: '', mobile: '', item_id: '', code: '', pageNo: 1, pageSize: 10, totalRecord: 0 },
      formData: {},
      countData: { loading: false, fcnum: 0, ytbnum: 0, zcnum: 0 },
      columns1: [
        { title: '社区名称', key: 'company_name', align: 'center' },
        { title: '社区账号', key: 'company_code', align: 'center' },
        { title: '办件量', key: 'num', align: 'center' },
        { title: '备份状态', slot: 'state', align: 'center' },
        { title: '操作', align: 'center', slot: 'action' }
      ],
      loadData: false,
      dataList: []
    }
  },
  methods: {
    selectlist (inpageNo) {
      this.loadData = true
      if (inpageNo) {
        this.params.pageNo = inpageNo
      } else {
        this.params.pageNo = 1
      }
      findBfList(this.params).then(ret => {
        if (ret.data.errcode === 0) {
          this.dataList = ret.data.data
          this.loadData = false
          this.params = {
            name: this.params.name,
            mobile: this.params.mobile,
            code: this.params.code,
            item_id: this.params.item_id
          }
        } else {
          this.loadData = true
          this.$Notice.error({
            title: '查询列表信息失败',
            desc: ret.data.errmsg
          })
        }
      })
    },
    addUnderWriter (row) {
      this.$Modal.confirm({
        title: '确定备份吗',
        onOk: () => {
          savebf({ company_code: row.company_code }).then(ret => {
            if (ret.data.errcode === 0) {
              this.selectlist()
              this.$Notice.success({ title: '备份成功!' })
            } else {
              this.loadData = true
              this.$Notice.error({
                title: '备份失败',
                desc: ret.data.errmsg
              })
            }
          })
        }
      })
    }
  },
  mounted () {
    this.selectlist()
  }
}
</script>

<style scoped>
.page_style {
  margin: 20px 5px;
}
.input-frame {
  width: 120px;
  margin-right: 10px;
}
.house-list > .group {
  background: white;
  padding: 10px;
  margin-top: 10px;
}
.house-list > .group > .item {
  border-bottom: 1px solid #f5f5f5;
  padding: 10px 0;
}
.house-list > .group > .item .top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
}
.house-list > .group > .item .title {
  font-size: 14px;
  color: #333333;
}
.house-list > .group > .item .address {
  font-size: 12px;
  color: gray;
  display: flex;
  align-items: center;
}
.house-list > .group > .item .detail {
  font-size: 12px;
  color: dodgerblue;
}
.opt-area-02 {
  display: flex;
  align-items: center;
  flex-direction: column;
  border: 1px solid #abdcff;
  background-color: #f0faff;
  padding: 8px 16px 8px 16px;
  border-radius: 4px;
  margin-bottom: 10px;
}
.opt-area-02 .right-con {
  width: 100%;
  margin-top: 5px;
  display: flex;
}
.opt-area-02 .left-con {
  font-size: 14px;
  width: 100%;
}
.opt-area-02 .left-con span {
  font-weight: bold;
}
.opt-area-02 .right-con input {
  width: 150px;
  margin-right: 10px;
}

.opt-area-02 .right-con .input-frame {
  width: 200px;
  margin-right: 10px;
}
.table-action-btn {
  margin-right: 3px;
}
.container >>> .ivu-btn-small {
  height: 24px;
  padding: 0 5px;
  font-size: 12px;
  border-radius: 3px;
}
.btn-action {
  margin-bottom: 10px;
}
.mp10 {
  margin-right: 10px;
}
.title-style {
  color: red;
}
.mb20 {
  margin-bottom: 20px;
}
.mt20 {
  margin-top: 20px;
}
.ivu-table-row {
  height: 57px;
}
.ivu-form-item{
  /*margin-bottom: 0%;*/
}
</style>
